/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matrimonybeans;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;

/**
 *
 * @author 4410s
 */
@Stateless
public class Candidate implements CandidateLocal {

    Connection conn;
    ResultSet rs = null;

    @Override
    public HashMap Manager_Candidate() {
        HashMap hmdataCandidate = new HashMap();
        try {
            ConnectDB conDB = new ConnectDB();
            conn = conDB.getConnection();
            String strSql = "SELECT * FROM Candidate ";
            PreparedStatement pstmt = conn.prepareCall(strSql);
            rs = pstmt.executeQuery();
            while (rs.next()) {
                HashMap hm = new HashMap();
                hm.put("username", rs.getString("username").trim());
                hm.put("email_id", rs.getString("email_id").trim());
                hm.put("first_name", rs.getString("first_name").trim());
                hm.put("middle_name", rs.getString("middle_name").trim());
                hm.put("last_name", rs.getString("last_name").trim());
                hm.put("avatar", rs.getString("avatar").trim());
                hm.put("gender", rs.getString("gender").trim());
                hm.put("marital_status", rs.getString("marital_status").trim());
                hmdataCandidate.put(rs.getString("username"), hm);
            }
        } catch (SQLException ex) {
            Logger.getLogger(Candidate.class.getName()).log(Level.SEVERE, null, ex);
        }
        return hmdataCandidate;
    }
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    boolean flag = false;

    @Override
    public Boolean Delete_Candidate_Data(int IDServices) {
        try {
            ConnectDB conDB = new ConnectDB();
            conn = conDB.getConnection();
            String strSql = "Delete Services where id_services=? ";
            PreparedStatement pstmt = conn.prepareCall(strSql);
            pstmt.setInt(1, IDServices);
            int count = 0;
            count = pstmt.executeUpdate();
            if (count > 0) {
                flag = true;
            } else {
                flag = false;
            }

        } catch (SQLException ex) {
            Logger.getLogger(Candidate.class.getName()).log(Level.SEVERE, null, ex);
        }
        return flag;
    }
}
